home *** CD-ROM | disk | FTP | other *** search
-
- #include "SerialDvr.h"
- #include "installer.h"
-
- /******** MAC global vars **********/
- Rect screen;
- int half_h,half_v;
- EventRecord theEvent;
- MenuHandle DeskMenu,FileMenu;
- Str255 theAcc;
- WindowPtr theWindow;
-
- /*********************************** test code here ********************************/
- DoIt()
- {
- SysEnvRec system;
- int result;
- int saveResFile;
- DialogPtr dd;
- int done;
- int itemHit;
- int t;
- Handle h;
- Rect r;
-
-
- if ( isInstalled() )
- {
-
- dd = GetNewDialog(129,nil,(WindowPtr)-1);
- if ( dd != nil )
- {
- ParamText("\pINSTALLED","\pREMOVE","\p","\p");
- GetDItem(dd,1,&t,&h,&r);
- SetCTitle(h,"\pREMOVE");
- installOutline(dd,5);
- done = NO;
- while (!done)
- {
- ModalDialog(nil,&itemHit);
- switch(itemHit)
- {
- case 1:
- doRemove();
- done = YES;
- break;
- case 2:
- done = YES;
- break;
- }
- }
- DisposDialog(dd);
- }
- else
- SysBeep(1);
- }
- else
- {
- dd = GetNewDialog(129,nil,(WindowPtr)-1);
- if ( dd != nil )
- {
- ParamText("\pNOT installed","\pINSTALL","\p","\p");
- GetDItem(dd,1,&t,&h,&r);
- SetCTitle(h,"\pINSTALL");
- installOutline(dd,5);
- done = NO;
- while (!done)
- {
- ModalDialog(nil,&itemHit);
- switch(itemHit)
- {
- case 1:
- doInstall();
- done = YES;
- break;
- case 2:
- done = YES;
- break;
- }
- }
- DisposDialog(dd);
- }
- else
- SysBeep(1);
- }
- }
-
- doInstall()
- {
- int t;
- Handle h;
- Rect r;
- DialogPtr dd;
- OSErr err = noErr;
- int done;
- int itemHit;
- long finalTicks;
- int saveResFile;
- Handle hh = nil;
- Handle MYhh = nil;
- Handle MYrov = nil;
- Handle MYrovq = nil;
-
- dd = GetNewDialog(130,nil,(WindowPtr)-1);
- ParamText("\pInstalling the WDEF patch.","\p","\p","\p");
- GetDItem(dd,1,&t,&h,&r);
- HideControl(h);
- DrawDialog(dd);
-
- /*get my patch from the program*/
- MYhh = GetResource('WDEF',68);
- if ( *MYhh == nil )
- LoadResource(MYhh);
- if ( MYhh == nil || *MYhh == nil)
- {
- SysBeep(1);SysBeep(1);SysBeep(1);return(resNotFound);
- }
- DetachResource(MYhh);
- HLock(MYhh);
-
- MYrov = GetResource('ROv#',0);
- if ( *MYrov == nil )
- LoadResource(MYrov);
- if ( MYrov == nil || *MYrov == nil )
- {
- SysBeep(1);SysBeep(1);SysBeep(1);return(resNotFound);
- }
- DetachResource(MYrov);
- HLock(MYrov);
-
- /*remember our res file number and set it to the system*/
- saveResFile = CurResFile();
- UseResFile(0);
-
-
- /*kill any existing 69 in the system file*/
- hh = GetResource('WDEF',69);
- if ( hh != nil )
- {
- RmveResource(hh);
- err = ResError();
- UpdateResFile(0);
- err = ResError();
- }
-
- /*update rov#*/
- hh = GetResource('ROv#',376);
- if ( hh != nil )
- {
- RmveResource(hh);
- err = ResError();
- UpdateResFile(0);
- err = ResError();
- }
- AddResource(MYrov,'ROv#',376,"\p][cx");
- err = ResError();
- UpdateResFile(0);
- err = ResError();
-
- MYrovq = NewHandle(8);
- AddResource(MYrovq,'ROv?',376,"\pwhat time is it hack");
- err = ResError();
- UpdateResFile(0);
- err = ResError();
-
- /*get the system's wdef#0 and write it to #69*/
- hh = GetResource('WDEF',0);
- if ( *hh == nil )
- LoadResource(hh);
- if ( hh == nil || *hh == nil )
- {
- SysBeep(1);SysBeep(1);SysBeep(1);return(resNotFound);
- }
- HLock(hh);
- DetachResource(hh);
- AddResource(hh,'WDEF',69,"\pOriginal WDEF #0");
- err = ResError();
- if ( err != noErr )
- {
- SysBeep(1);SysBeep(1);SysBeep(1);return(err);
- }
- WriteResource(hh);
- ReleaseResource(hh);
-
-
- /*get the system's wdef#0 again and remove it*/
- hh = GetResource('WDEF',0);
- if ( hh == nil )
- {
- SysBeep(1);SysBeep(1);SysBeep(1);return(resNotFound);
- }
- RmveResource(hh);
- UpdateResFile(0);
-
-
- /*add my resource in place of the old #0*/
- AddResource(MYhh,'WDEF',0,"\pEric's WDEF");
- WriteResource(MYhh);
- ReleaseResource(MYhh);
-
-
- /*point the current res file to us*/
- UseResFile(saveResFile);
-
-
- /*tell'em it's done*/
- if ( err == noErr )
- ParamText("\pWDEF patch sucessfully installed.","\p","\p","\p");
- else
- ParamText("\pThere was an error installing the WDEF patch.","\p","\p","\p");
-
- installOutline(dd,4);
- GetDItem(dd,1,&t,&h,&r);
- ShowControl(h);
-
- done = NO;
- while (!done)
- {
- ModalDialog(nil,&itemHit);
- switch(itemHit)
- {
- case 1:
- done = YES;
- break;
- }
- }
- DisposDialog(dd);
- }
-
- doRemove()
- {
- int t;
- Handle h;
- Rect r;
- DialogPtr dd;
- OSErr err = noErr;
- int done;
- int itemHit;
- long finalTicks;
- int saveResFile;
- Handle hh = nil;
- Handle MYhh = nil;
- Handle MYrov = nil;
- Handle MYtest = nil;
-
- dd = GetNewDialog(130,nil,(WindowPtr)-1);
- ParamText("\pRemoving the WDEF patch.","\p","\p","\p");
- GetDItem(dd,1,&t,&h,&r);
- HideControl(h);
- DrawDialog(dd);
-
- MYrov = GetResource('ROv#',1);
- if ( *MYrov == nil )
- LoadResource(MYrov);
- if ( MYrov == nil || *MYrov == nil )
- {
- SysBeep(1);SysBeep(1);SysBeep(1);return(resNotFound);
- }
- DetachResource(MYrov);
- HLock(MYrov);
-
- saveResFile = CurResFile();
- UseResFile(0);
-
- MYtest = GetResource('ROv?',376);
- if ( MYtest == nil )
- {
- MYhh = GetResource('WDEF',69);
- if ( *MYhh == nil )
- LoadResource(MYhh);
- if ( MYhh == nil || *MYhh == nil)
- return(resNotFound);
- DetachResource(MYhh);
- HLock(MYhh);
-
- hh = GetResource('WDEF',0);
- if ( *hh == nil )
- LoadResource(hh);
- if ( hh == nil || *hh == nil )
- return(resNotFound);
- HLock(hh);
-
- RmveResource(hh);
- AddResource(MYhh,'WDEF',0,"\p");
-
- hh = GetResource('WDEF',69);
- HLock(hh);
- RmveResource(hh);
-
- WriteResource(MYhh);
- ReleaseResource(MYhh);
- }
- else
- {
- /*update rov#*/
- RmveResource(MYtest);
- UpdateResFile(0);
- hh = GetResource('ROv#',376);
- if ( hh != nil )
- {
- RmveResource(hh);
- err = ResError();
- UpdateResFile(0);
- err = ResError();
- }
- AddResource(MYrov,'ROv#',376,"\p");
- WriteResource(MYrov);
- err = ResError();
- UpdateResFile(0);
- err = ResError();
- }
-
- UseResFile(saveResFile);
-
- if ( err == noErr )
- ParamText("\pWDEF patch sucessfully removed.","\p","\p","\p");
- else
- ParamText("\pThere was an error removing the WDEF patch.","\p","\p","\p");
-
- installOutline(dd,4);
- GetDItem(dd,1,&t,&h,&r);
- ShowControl(h);
-
- done = NO;
- while (!done)
- {
- ModalDialog(nil,&itemHit);
- switch(itemHit)
- {
- case 1:
- done = YES;
- break;
- }
- }
- DisposDialog(dd);
- }
- int isInstalled()
- {
- SysEnvRec system;
- int result;
- int saveResFile;
- Handle hh = nil;
-
- saveResFile = CurResFile();
- UseResFile(0);
-
- if ( hh == nil )
- hh = GetResource('WDEF',0);
-
- if ( *hh == nil )
- LoadResource(hh);
-
- HLock(hh);
- if ( isMyString(hh) )
- result = TRUE;
- else
- result = FALSE;
-
- UseResFile(saveResFile);
- return(result);
- }
-
- int isMyString(hh)
- Handle hh;
- {
- if (*(long *)&(*hh)[8] == 'Eric')
- return(TRUE);
- else
- return(FALSE);
- }
-
- /*********************************** dumb shell here ******************************/
-
-
- /*This is what runs when the Bomb dialog box comes up, this Hilites the resume button*/
- reStartProc()
- {
- ExitToShell();
- }
-
- Inits()
- {
- MaxApplZone ();
- MoreMasters ();
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitCursor();
- InitDialogs(reStartProc);
-
- FlushEvents(everyEvent, nil);
-
- SetRect(&screen,
- screenBits.bounds.left,
- screenBits.bounds.top,
- screenBits.bounds.right,
- screenBits.bounds.bottom);
-
- /*center of the screen*/
- half_h = (screenBits.bounds.right / 2);
- half_v = (screenBits.bounds.bottom / 2);
- }
-
- SetUpMenus()
- {
- long items;
-
- /* Desk Accessory Menu*/
- DeskMenu = NewMenu (Desk_ID,"\p\24");
- AppendMenu (DeskMenu,"\pAbout Eric's work shell...;(-");
- AddResMenu (DeskMenu, 'DRVR');
- items = CountMItems(DeskMenu);
- InsertMenu (DeskMenu, 0);
-
- /* file menu */
- FileMenu = NewMenu (File_ID,"\pFile");
- AppendMenu (FileMenu,"\pDo it./G;(-;Quit/Q");
- InsertMenu (FileMenu, 0);
-
- DrawMenuBar();
- }
-
- OpenWindow()
- {
- Point tempPt;
- int Offset;
- Rect bounds;
- SetRect(&bounds,100,100,200,200);
-
- theWindow = GetNewWindow(1000,nil, (WindowPtr)-1);
-
- SetPort(theWindow);
- tempPt.v = theWindow->portRect.top;
- tempPt.h = theWindow->portRect.left;
- LocalToGlobal(&tempPt);
- Offset = ((half_h*2) - (theWindow->portRect.right-theWindow->portRect.left))/2;
- MoveWindow(theWindow,Offset,tempPt.v,FALSE);
- ShowWindow(theWindow);
- }
-
-
- main()
- {
- WindowPtr whichWindow;
- short windowcode;
- char c;
- WindowPtr savePort;
- int stillInGoAway;
- Rect tempRect;
- long Result;
- Point myPt;
-
- Inits();
- SetUpMenus();
- /*OpenWindow();*/
-
- while (TRUE)
- {
- if (GetNextEvent(everyEvent,&theEvent))
- {
- SystemTask();
- switch (theEvent.what)
- {
- case mouseDown:
- windowcode=FindWindow(Pt2ROM(theEvent.where),&whichWindow);
- switch (windowcode)
- {
- case inMenuBar:
- DoMenu(MenuSelect(Pt2ROM(theEvent.where)));
- break;
- case inSysWindow:
- SystemClick(&theEvent,whichWindow);
- break;
- case inDrag:
- if (whichWindow != nil)
- DragWindow(whichWindow,theEvent.where,&screen);
- break;
- case inGoAway:
- stillInGoAway = TrackGoAway(whichWindow,Pt2ROM(theEvent.where));
- if(stillInGoAway == TRUE)
- ExitToShell();
- break;
- case inGrow:
- SetRect(&tempRect,50,50,screen.right,screen.bottom);
- Result = GrowWindow(whichWindow, theEvent.where, &tempRect);
- if ( Result != nil )
- SizeWindow(whichWindow, LoWord(Result), HiWord(Result), TRUE);
- break;
- case inZoomIn:
- case inZoomOut:
- windowcode = FindWindow(theEvent.where,&whichWindow);
- if (whichWindow != nil)
- {
- GetPort(&savePort);
- SetPort(whichWindow);
-
- myPt = theEvent.where;
- GlobalToLocal(&myPt);
-
- if (TrackBox(whichWindow,myPt, windowcode))
- ZoomWindow(whichWindow, windowcode, TRUE);
- }
- break;
- }
- break;
- case keyDown:
- if (theEvent.modifiers & cmdKey)
- {
- c = theEvent.message & charCodeMask;
- DoMenu(MenuKey(c));
- }
- break;
-
- } /*switch*/
- } /*if(GNE)*/
- } /*while(true)*/
- } /* end of main() */
-
-
- DoMenu(menuResult)
- long menuResult;
- {
- short menuID, itemNumber,i;
- Str255 theItem;
-
- menuID = HiWord (menuResult);
- itemNumber = LoWord (menuResult);
-
- switch (menuID)
- {
- case Desk_ID:
- switch(itemNumber)
- {
- case 1:
- doAbout();
- break;
- default:
- GetItem(DeskMenu,itemNumber, &theAcc);
- OpenDeskAcc(&theAcc);
- break;
- }
- break;
- case File_ID:
- switch (itemNumber)
- {
- case fm_doit:
- DoIt();
- break;
- case fm_quit:
- ExitToShell();
- break;
- }
- break;
- }
- HiliteMenu(0);
- }
-
- doAbout()
- {
- int r = Alert(1000,0L);
- }